Skip to content

Conversation

@amyssnippet
Copy link

@amyssnippet amyssnippet commented Jan 24, 2026

this PR implements socket.setTOS(tos) and socket.getTOS() in net.Socket. it needed this to support DSCP tagging (QoS) for traffic prioritization, which wasn't previously exposed in the JS API. for the implementation:

  • I added the logic in tcp_wrap.cc to attempt IP_TOS first, and fallback to IPV6_TCLASS if that fails. This handles both IPv4 and IPv6 sockets automatically without needing a separate flag.
  • Windows returns UV_ENOSYS for now since the headers/implementation differ there.
  • Added a new test file (test-net-socket-tos.js) to verify input validation and ensure the values are actually set on supported platforms.

Fixes: #61489

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jan 24, 2026
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. Can you add the documentation?

@mcollina mcollina requested a review from ronag January 24, 2026 13:16
@mcollina mcollina added the semver-minor PRs that contain new features and should be released in the next minor version. label Jan 24, 2026
@amyssnippet amyssnippet requested a review from mcollina January 24, 2026 13:41
@amyssnippet amyssnippet mentioned this pull request Jan 24, 2026
@amyssnippet amyssnippet requested a review from mcollina January 24, 2026 14:34
@amyssnippet
Copy link
Author

Thanks @mcollina , is this ready to be merged? Please let me know if there is anything else you need me to adjust.

@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 25, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 25, 2026
@nodejs-github-bot
Copy link
Collaborator

@ronag
Copy link
Member

ronag commented Jan 25, 2026

@mcollina I'm confused by the CI failures. Any ideas? Or just flaky?

@amyssnippet
Copy link
Author

@ronag check now, i guess everything including ci should work. have a look. Thanks!

@ronag ronag added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jan 26, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 26, 2026
@nodejs-github-bot
Copy link
Collaborator

@ronag
Copy link
Member

ronag commented Jan 26, 2026

@amyssnippet: based on your solution I assume that libuv doesn't have an api for this... maybe would be an idea to open an issue over there as well?

@ronag ronag requested a review from Copilot January 26, 2026 11:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@amyssnippet
Copy link
Author

amyssnippet commented Jan 26, 2026

@amyssnippet: based on your solution I assume that libuv doesn't have an api for this... maybe would be an idea to open an issue over there as well?

i guess you are right @ronag
i read this https://docs.libuv.org/en/v1.x/guide/networking.html and found out there is missing API we need and thats why i was using raw setsockopt calls on the file descriptor.
Since getting a new feature into libuv and waiting for it to roll into Node.js would take a significant amount of time, could we land this implementation now to unblock the feature for users?
we need to add a feature request upstream in the libuv repo to add proper uv_tcp_set_tos API, and we can refactor this code to use that API once it is available.
rn i have done the #ifdef things, which is temp and pragmatic way, if we have to work on this properly, then we should consider contributing libuv.
what are your thoughts??

@amyssnippet
Copy link
Author

and also i have observed some flaky ci tests here, should i report them as issues? or just paste them here so the internal team fixed them??

@amyssnippet
Copy link
Author

libuv/libuv#2536
I found someone tried back in 2019. but got stalled for 5 years, but waiting for an upstream API seems risky.
By landing this setsockopt implementation in Node.js now, we unblock high-performance media applications immediately. should we open a new issue in libuv to revive the discussion, but I strongly believe we shouldn't block this PR on it.

@amyssnippet
Copy link
Author

@ronag after inspecting some of errors in ci, i rolled some changes, kindle approve the ci once again so i can futher improve the checks

@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 26, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 26, 2026
@nodejs-github-bot
Copy link
Collaborator

@anonrig
Copy link
Member

anonrig commented Jan 26, 2026

What does TOS stand for?

@ronag
Copy link
Member

ronag commented Jan 26, 2026

What does TOS stand for?

https://en.wikipedia.org/wiki/Type_of_service

doc/api/net.md Outdated
@@ -1461,6 +1461,45 @@ If `timeout` is 0, then the existing idle timeout is disabled.
The optional `callback` parameter will be added as a one-time listener for the
[`'timeout'`][] event.

### `socket.getTOS()`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our API names in Node.js are generally more verbose than the corresponding OS APIs – would there be anything speaking against calling these socket.getTypeOfService() and socket.setTypeOfService()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense and i agree to that, i will update to use full names

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax i have used full names now, check the latest changes

} else {
args.GetReturnValue().Set(uv_translate_sys_error(errno));
}
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say this needs to block this PR, but upstreaming these additions to https://github.com/libuv/libuv might be a good follow-up change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even i was thinking the same, if internal members of nodejs will work and do the changes over there to libuv, then additions will be fast, rather than i do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can open an issue there pointing to this PR, that will help and maybe someone picks it up.

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 54.62185% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.88%. Comparing base (5d39030) to head (c39d13e).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
src/tcp_wrap.cc 48.33% 18 Missing and 13 partials ⚠️
lib/net.js 61.01% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61503      +/-   ##
==========================================
- Coverage   89.82%   88.88%   -0.94%     
==========================================
  Files         667      672       +5     
  Lines      203693   203928     +235     
  Branches    39163    39129      -34     
==========================================
- Hits       182963   181259    -1704     
- Misses      13061    14933    +1872     
- Partials     7669     7736      +67     
Files with missing lines Coverage Δ
src/tcp_wrap.h 71.42% <ø> (ø)
lib/net.js 93.67% <61.01%> (-1.62%) ⬇️
src/tcp_wrap.cc 69.68% <48.33%> (-4.93%) ⬇️

... and 121 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

socket.setTOS

7 participants